@namespace RazorConsole.Components

@using System.Collections.Generic
@using System.Globalization
@using System.Linq
@using System.Xml.Linq
@using Microsoft.AspNetCore.Components
@using RazorConsole.Core.Rendering.ComponentMarkup
@using Spectre.Console
@using Spectre.Console.Rendering
<div class="align"
     data-horizontal="@HorizontalAttribute"
     data-vertical="@VerticalAttribute"
     data-width="@WidthAttribute"
    data-height="@HeightAttribute">
    @ChildContent
</div>

@code {
    [Parameter]
    public RenderFragment? ChildContent { get; set; }

    [Parameter]
    public HorizontalAlignment Horizontal { get; set; } = HorizontalAlignment.Left;

    [Parameter]
    public VerticalAlignment Vertical { get; set; } = VerticalAlignment.Top;

    [Parameter]
    public int? Width { get; set; }

    [Parameter]
    public int? Height { get; set; }

    private string HorizontalAttribute => Horizontal.ToString().ToLowerInvariant();

    private string VerticalAttribute => Vertical.ToString().ToLowerInvariant();

    private string? WidthAttribute => Width.HasValue && Width.Value > 0
        ? Width.Value.ToString(CultureInfo.InvariantCulture)
        : null;

    private string? HeightAttribute => Height.HasValue && Height.Value > 0
        ? Height.Value.ToString(CultureInfo.InvariantCulture)
        : null;
}
